{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课后作业：选取三家人脸识别API进行调用\n",
    "- 选取3家人脸识别API，每家API实现3张照片（1张单人、2张多人），比较算出來的年纪、性別及情绪內容并做出这3家API不同之处的结论，【总成绩+2.5分】\n",
    "- 最少需做1家人脸识别API，并实现3张照片（1张单人、2张多人）的年级、性别及情绪，【少于1家总成绩-1分】\n",
    "- 提交HTML档，命名为【姓名-X家API-学号】\n",
    "- - -\n",
    "\n",
    "#### - 选择azure 、face++、百度智能云的人脸识别API进行调用\n",
    "#### -选择一张单人、一张四人、一张七人照片尝试\n",
    "## 1.使用Azure API实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '794f0833-8637-48ca-8cb7-af1d3aa6f8c6',\n",
       "  'faceRectangle': {'top': 310, 'left': 556, 'width': 489, 'height': 489},\n",
       "  'faceAttributes': {'gender': 'male',\n",
       "   'age': 21.0,\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0}}}]"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入需要的requests模块\n",
    "import requests\n",
    "import json\n",
    "\n",
    "# 输入API_Key\n",
    "KEY = '13a8027eaa9944f1b6885cdaaa74e878' \n",
    "\n",
    "BASE_URL = 'https://face-ll.cognitiveservices.azure.com/face/v1.0/detect' \n",
    "\n",
    "HEADERS = {\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': '{}'.format(KEY),   \n",
    "}\n",
    "# 一张单人照\n",
    "img_url_01 = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586710673935&di=0e2ba0e28894647a6f7bf59adc1a8d01&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201801%2F18%2F20180118203124_YKMew.jpeg'\n",
    "\n",
    "\n",
    "data = {\n",
    "    'url': '{}'.format(img_url_01),    \n",
    "}\n",
    "\n",
    "payload = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'flase',\n",
    "    'returnFaceAttributes': '{}'.format('age,gender,emotion'), \n",
    "}\n",
    "\n",
    "r = requests.post(BASE_URL,data=json.dumps(data),params = payload,headers=HEADERS)\n",
    "\n",
    "#查看状态码\n",
    "r.status_code\n",
    "\n",
    "#查看内容\n",
    "r.content\n",
    "\n",
    "#将结果转化为json\n",
    "results = r.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.emotion.anger</th>\n",
       "      <th>faceAttributes.emotion.contempt</th>\n",
       "      <th>faceAttributes.emotion.disgust</th>\n",
       "      <th>faceAttributes.emotion.fear</th>\n",
       "      <th>faceAttributes.emotion.happiness</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.emotion.sadness</th>\n",
       "      <th>faceAttributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>faceId</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>794f0833-8637-48ca-8cb7-af1d3aa6f8c6</th>\n",
       "      <td>male</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     faceAttributes.gender  \\\n",
       "faceId                                                       \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                  male   \n",
       "\n",
       "                                      faceAttributes.age  \\\n",
       "faceId                                                     \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                21.0   \n",
       "\n",
       "                                      faceAttributes.emotion.anger  \\\n",
       "faceId                                                               \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                           0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.contempt  \\\n",
       "faceId                                                                  \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                              0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.disgust  \\\n",
       "faceId                                                                 \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                             0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.fear  \\\n",
       "faceId                                                              \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                          0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.happiness  \\\n",
       "faceId                                                                   \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                               1.0   \n",
       "\n",
       "                                      faceAttributes.emotion.neutral  \\\n",
       "faceId                                                                 \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                             0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.sadness  \\\n",
       "faceId                                                                 \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                             0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.surprise  \n",
       "faceId                                                                 \n",
       "794f0833-8637-48ca-8cb7-af1d3aa6f8c6                              0.0  "
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用pandas黑魔法\n",
    "import pandas as pd\n",
    "from pandas.io.json import json_normalize\n",
    "df = pd.json_normalize(results)\n",
    "df = df.set_index('faceId')\n",
    "df = df.iloc[:,4:]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'faceId': '9efd8bf1-6182-443d-bfb2-a2f88c945f80', 'faceRectangle': {'top': 49, 'left': 49, 'width': 48, 'height': 48}, 'faceAttributes': {'gender': 'male', 'age': 19.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.951, 'neutral': 0.049, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': '7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771', 'faceRectangle': {'top': 66, 'left': 354, 'width': 44, 'height': 44}, 'faceAttributes': {'gender': 'male', 'age': 19.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.998, 'neutral': 0.002, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': '1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0', 'faceRectangle': {'top': 90, 'left': 138, 'width': 42, 'height': 42}, 'faceAttributes': {'gender': 'female', 'age': 21.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 1.0, 'neutral': 0.0, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': '18cef2b9-cb58-419f-bbe9-01f228cbdcf4', 'faceRectangle': {'top': 92, 'left': 241, 'width': 40, 'height': 40}, 'faceAttributes': {'gender': 'female', 'age': 20.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.011, 'neutral': 0.987, 'sadness': 0.002, 'surprise': 0.001}}}]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.emotion.anger</th>\n",
       "      <th>faceAttributes.emotion.contempt</th>\n",
       "      <th>faceAttributes.emotion.disgust</th>\n",
       "      <th>faceAttributes.emotion.fear</th>\n",
       "      <th>faceAttributes.emotion.happiness</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.emotion.sadness</th>\n",
       "      <th>faceAttributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>faceId</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9efd8bf1-6182-443d-bfb2-a2f88c945f80</th>\n",
       "      <td>male</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.951</td>\n",
       "      <td>0.049</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771</th>\n",
       "      <td>male</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.998</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0</th>\n",
       "      <td>female</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18cef2b9-cb58-419f-bbe9-01f228cbdcf4</th>\n",
       "      <td>female</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.011</td>\n",
       "      <td>0.987</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     faceAttributes.gender  \\\n",
       "faceId                                                       \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                  male   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                  male   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                female   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                female   \n",
       "\n",
       "                                      faceAttributes.age  \\\n",
       "faceId                                                     \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                19.0   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                19.0   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                21.0   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                20.0   \n",
       "\n",
       "                                      faceAttributes.emotion.anger  \\\n",
       "faceId                                                               \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                           0.0   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                           0.0   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                           0.0   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                           0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.contempt  \\\n",
       "faceId                                                                  \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                              0.0   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                              0.0   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                              0.0   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                              0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.disgust  \\\n",
       "faceId                                                                 \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                             0.0   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                             0.0   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                             0.0   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                             0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.fear  \\\n",
       "faceId                                                              \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                          0.0   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                          0.0   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                          0.0   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                          0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.happiness  \\\n",
       "faceId                                                                   \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                             0.951   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                             0.998   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                             1.000   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                             0.011   \n",
       "\n",
       "                                      faceAttributes.emotion.neutral  \\\n",
       "faceId                                                                 \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                           0.049   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                           0.002   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                           0.000   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                           0.987   \n",
       "\n",
       "                                      faceAttributes.emotion.sadness  \\\n",
       "faceId                                                                 \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                           0.000   \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                           0.000   \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                           0.000   \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                           0.002   \n",
       "\n",
       "                                      faceAttributes.emotion.surprise  \n",
       "faceId                                                                 \n",
       "9efd8bf1-6182-443d-bfb2-a2f88c945f80                            0.000  \n",
       "7b824ef4-1b2c-4462-9fd3-cd5a3e8ba771                            0.000  \n",
       "1f8c2cc1-d383-4716-a385-4ab9cd3a3ab0                            0.000  \n",
       "18cef2b9-cb58-419f-bbe9-01f228cbdcf4                            0.001  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入一张四人照\n",
    "img_url_02 = 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=895667226,563348569&fm=26&gp=0.jpg'\n",
    "\n",
    "data = {\n",
    "    'url': '{}'.format(img_url_02),\n",
    "}\n",
    "\n",
    "r4 = requests.post(BASE_URL,data=json.dumps(data),params = payload,headers=HEADERS)\n",
    "results4 = r4.json()\n",
    "print(results4)\n",
    "\n",
    "df4 = pd.json_normalize(results1)\n",
    "df4 = df4.set_index('faceId')\n",
    "df4 = df4.iloc[:,4:]\n",
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'faceId': 'e77be821-1554-434a-9701-0bee2ed6f3ba', 'faceRectangle': {'top': 355, 'left': 707, 'width': 77, 'height': 77}, 'faceAttributes': {'gender': 'male', 'age': 19.0, 'emotion': {'anger': 0.0, 'contempt': 0.001, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.548, 'neutral': 0.45, 'sadness': 0.001, 'surprise': 0.0}}}, {'faceId': 'c9645cf4-9322-417a-a5bd-154d042c90ee', 'faceRectangle': {'top': 270, 'left': 357, 'width': 69, 'height': 69}, 'faceAttributes': {'gender': 'male', 'age': 24.0, 'emotion': {'anger': 0.0, 'contempt': 0.001, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.001, 'neutral': 0.998, 'sadness': 0.001, 'surprise': 0.0}}}, {'faceId': 'a062a362-9db5-49be-bfa3-89ccf5a696d3', 'faceRectangle': {'top': 267, 'left': 538, 'width': 62, 'height': 62}, 'faceAttributes': {'gender': 'female', 'age': 19.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 1.0, 'neutral': 0.0, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': '14d33869-72e9-46d2-99d2-b2311cea42c7', 'faceRectangle': {'top': 84, 'left': 642, 'width': 55, 'height': 55}, 'faceAttributes': {'gender': 'male', 'age': 23.0, 'emotion': {'anger': 0.0, 'contempt': 0.001, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.74, 'neutral': 0.259, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': 'a116adbe-21b9-4318-acc7-4d2aebed05dd', 'faceRectangle': {'top': 192, 'left': 650, 'width': 52, 'height': 52}, 'faceAttributes': {'gender': 'female', 'age': 30.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 1.0, 'neutral': 0.0, 'sadness': 0.0, 'surprise': 0.0}}}, {'faceId': '01418f73-29a6-4482-af5e-647439c47fe7', 'faceRectangle': {'top': 188, 'left': 419, 'width': 51, 'height': 51}, 'faceAttributes': {'gender': 'male', 'age': 20.0, 'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.983, 'neutral': 0.015, 'sadness': 0.001, 'surprise': 0.0}}}, {'faceId': 'a183b399-c817-4239-bf0f-78a765010afe', 'faceRectangle': {'top': 79, 'left': 717, 'width': 50, 'height': 50}, 'faceAttributes': {'gender': 'female', 'age': 24.0, 'emotion': {'anger': 0.0, 'contempt': 0.001, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.009, 'neutral': 0.739, 'sadness': 0.25, 'surprise': 0.001}}}]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.emotion.anger</th>\n",
       "      <th>faceAttributes.emotion.contempt</th>\n",
       "      <th>faceAttributes.emotion.disgust</th>\n",
       "      <th>faceAttributes.emotion.fear</th>\n",
       "      <th>faceAttributes.emotion.happiness</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.emotion.sadness</th>\n",
       "      <th>faceAttributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>faceId</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>e77be821-1554-434a-9701-0bee2ed6f3ba</th>\n",
       "      <td>male</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.548</td>\n",
       "      <td>0.450</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c9645cf4-9322-417a-a5bd-154d042c90ee</th>\n",
       "      <td>male</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.998</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a062a362-9db5-49be-bfa3-89ccf5a696d3</th>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14d33869-72e9-46d2-99d2-b2311cea42c7</th>\n",
       "      <td>male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.740</td>\n",
       "      <td>0.259</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a116adbe-21b9-4318-acc7-4d2aebed05dd</th>\n",
       "      <td>female</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>01418f73-29a6-4482-af5e-647439c47fe7</th>\n",
       "      <td>male</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.983</td>\n",
       "      <td>0.015</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a183b399-c817-4239-bf0f-78a765010afe</th>\n",
       "      <td>female</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.009</td>\n",
       "      <td>0.739</td>\n",
       "      <td>0.250</td>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     faceAttributes.gender  \\\n",
       "faceId                                                       \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                  male   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                  male   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                female   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                  male   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                female   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                  male   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                female   \n",
       "\n",
       "                                      faceAttributes.age  \\\n",
       "faceId                                                     \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                19.0   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                24.0   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                19.0   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                23.0   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                30.0   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                20.0   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                24.0   \n",
       "\n",
       "                                      faceAttributes.emotion.anger  \\\n",
       "faceId                                                               \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                           0.0   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                           0.0   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                           0.0   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                           0.0   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                           0.0   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                           0.0   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                           0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.contempt  \\\n",
       "faceId                                                                  \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                            0.001   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                            0.001   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                            0.000   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                            0.001   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                            0.000   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                            0.000   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                            0.001   \n",
       "\n",
       "                                      faceAttributes.emotion.disgust  \\\n",
       "faceId                                                                 \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                             0.0   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                             0.0   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                             0.0   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                             0.0   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                             0.0   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                             0.0   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                             0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.fear  \\\n",
       "faceId                                                              \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                          0.0   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                          0.0   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                          0.0   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                          0.0   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                          0.0   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                          0.0   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                          0.0   \n",
       "\n",
       "                                      faceAttributes.emotion.happiness  \\\n",
       "faceId                                                                   \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                             0.548   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                             0.001   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                             1.000   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                             0.740   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                             1.000   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                             0.983   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                             0.009   \n",
       "\n",
       "                                      faceAttributes.emotion.neutral  \\\n",
       "faceId                                                                 \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                           0.450   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                           0.998   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                           0.000   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                           0.259   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                           0.000   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                           0.015   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                           0.739   \n",
       "\n",
       "                                      faceAttributes.emotion.sadness  \\\n",
       "faceId                                                                 \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                           0.001   \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                           0.001   \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                           0.000   \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                           0.000   \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                           0.000   \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                           0.001   \n",
       "a183b399-c817-4239-bf0f-78a765010afe                           0.250   \n",
       "\n",
       "                                      faceAttributes.emotion.surprise  \n",
       "faceId                                                                 \n",
       "e77be821-1554-434a-9701-0bee2ed6f3ba                            0.000  \n",
       "c9645cf4-9322-417a-a5bd-154d042c90ee                            0.000  \n",
       "a062a362-9db5-49be-bfa3-89ccf5a696d3                            0.000  \n",
       "14d33869-72e9-46d2-99d2-b2311cea42c7                            0.000  \n",
       "a116adbe-21b9-4318-acc7-4d2aebed05dd                            0.000  \n",
       "01418f73-29a6-4482-af5e-647439c47fe7                            0.000  \n",
       "a183b399-c817-4239-bf0f-78a765010afe                            0.001  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入一张7人照\n",
    "img_url_03 = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586756754217&di=b0f52a3b6e62df4bb64eb633d780e5ef&imgtype=0&src=http%3A%2F%2Fn1.itc.cn%2Fimg8%2Fwb%2Frecom%2F2016%2F04%2F26%2F146167243273557991.JPEG'\n",
    "\n",
    "data = {\n",
    "    'url': '{}'.format(img_url_03),\n",
    "}\n",
    "\n",
    "r7 = requests.post(BASE_URL,data=json.dumps(data),params = payload,headers=HEADERS)\n",
    "\n",
    "results7 = r7.json()\n",
    "print(results7)\n",
    "\n",
    "df7 = pd.json_normalize(results7)\n",
    "df7 = df7.set_index('faceId')\n",
    "df7 = df7.iloc[:,4:]\n",
    "df7"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# #  face++ Detect API(面部检测)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1586952521,313c4beb-9e45-420c-bf03-23e3d190a1df', 'time_used': 318, 'faces': [{'face_token': '2747405ed1d7471626856406b228054c', 'face_rectangle': {'top': 338, 'left': 619, 'width': 516, 'height': 516}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 34}, 'emotion': {'anger': 0.009, 'disgust': 0.02, 'fear': 0.153, 'happiness': 99.789, 'neutral': 0.004, 'sadness': 0.021, 'surprise': 0.004}}}], 'image_id': 'De9JXICwRHYWYREl3iYcKA==', 'face_num': 1}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <th>attributes.age.value</th>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>516</td>\n",
       "      <td>Female</td>\n",
       "      <td>34</td>\n",
       "      <td>0.009</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.153</td>\n",
       "      <td>99.789</td>\n",
       "      <td>0.004</td>\n",
       "      <td>0.021</td>\n",
       "      <td>0.004</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   face_rectangle.height attributes.gender.value  attributes.age.value  \\\n",
       "0                    516                  Female                    34   \n",
       "\n",
       "   attributes.emotion.anger  attributes.emotion.disgust  \\\n",
       "0                     0.009                        0.02   \n",
       "\n",
       "   attributes.emotion.fear  attributes.emotion.happiness  \\\n",
       "0                    0.153                        99.789   \n",
       "\n",
       "   attributes.emotion.neutral  attributes.emotion.sadness  \\\n",
       "0                       0.004                       0.021   \n",
       "\n",
       "   attributes.emotion.surprise  \n",
       "0                        0.004  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "api_secret = \"LmJuv2ZfWMmW9ycKkr3FQEs1R3P4gKhz\"\n",
    "# 2、输入我们API_Key\n",
    "api_key = '1-Jj0t9l5lCIe_VpJHOXa8xBegILCeqO'  # Replace with a valid Subscription Key here.\n",
    "\n",
    "\n",
    "# 3、目标url\n",
    "# 这里也可以使用本地图片 例如：filepath =\"image/tupian.jpg\"\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "# 选择的照片为25岁男性单人照\n",
    "img_url_01 = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586710673935&di=0e2ba0e28894647a6f7bf59adc1a8d01&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201801%2F18%2F20180118203124_YKMew.jpeg'\n",
    "\n",
    "\n",
    "# 4、沿用API文档的示范代码,准备我们的headers和图片(数据)\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "# 5、准备symbol ? 后面的数据\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url_01,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,emotion', \n",
    "}\n",
    "\n",
    "face_r = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "face_r.status_code\n",
    "\n",
    "face_r = face_r.json() \n",
    "print(face_r)\n",
    "\n",
    "# pandas黑魔法形成表格\n",
    "face_df =  pd.json_normalize(face_r,record_path='faces')\n",
    "face_df = face_df .iloc[:,4:]\n",
    "face_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- face++的检测结果为34岁女性，与原图片25岁男性的信息有很大误差！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <th>attributes.age.value</th>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>a6c99d03a66ccb104dc74c747636462b</td>\n",
       "      <td>53</td>\n",
       "      <td>48</td>\n",
       "      <td>49</td>\n",
       "      <td>49</td>\n",
       "      <td>Male</td>\n",
       "      <td>23</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.002</td>\n",
       "      <td>57.600</td>\n",
       "      <td>41.870</td>\n",
       "      <td>0.523</td>\n",
       "      <td>0.002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>113ba98fac6dc155b9b0f65107c0161b</td>\n",
       "      <td>69</td>\n",
       "      <td>354</td>\n",
       "      <td>45</td>\n",
       "      <td>45</td>\n",
       "      <td>Male</td>\n",
       "      <td>26</td>\n",
       "      <td>0.008</td>\n",
       "      <td>1.804</td>\n",
       "      <td>0.012</td>\n",
       "      <td>97.936</td>\n",
       "      <td>0.023</td>\n",
       "      <td>0.083</td>\n",
       "      <td>0.135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>666584f95fc8d8487b451cdbd6d5f475</td>\n",
       "      <td>94</td>\n",
       "      <td>142</td>\n",
       "      <td>41</td>\n",
       "      <td>41</td>\n",
       "      <td>Female</td>\n",
       "      <td>22</td>\n",
       "      <td>0.011</td>\n",
       "      <td>0.426</td>\n",
       "      <td>0.026</td>\n",
       "      <td>44.509</td>\n",
       "      <td>0.021</td>\n",
       "      <td>54.835</td>\n",
       "      <td>0.172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4c111de2a2c5aa1123dbd716a85cd6ba</td>\n",
       "      <td>95</td>\n",
       "      <td>244</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>Female</td>\n",
       "      <td>23</td>\n",
       "      <td>0.397</td>\n",
       "      <td>4.949</td>\n",
       "      <td>20.876</td>\n",
       "      <td>14.339</td>\n",
       "      <td>29.111</td>\n",
       "      <td>9.857</td>\n",
       "      <td>20.470</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  a6c99d03a66ccb104dc74c747636462b                  53                   48   \n",
       "1  113ba98fac6dc155b9b0f65107c0161b                  69                  354   \n",
       "2  666584f95fc8d8487b451cdbd6d5f475                  94                  142   \n",
       "3  4c111de2a2c5aa1123dbd716a85cd6ba                  95                  244   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height attributes.gender.value  \\\n",
       "0                    49                     49                    Male   \n",
       "1                    45                     45                    Male   \n",
       "2                    41                     41                  Female   \n",
       "3                    39                     39                  Female   \n",
       "\n",
       "   attributes.age.value  attributes.emotion.anger  attributes.emotion.disgust  \\\n",
       "0                    23                     0.002                       0.002   \n",
       "1                    26                     0.008                       1.804   \n",
       "2                    22                     0.011                       0.426   \n",
       "3                    23                     0.397                       4.949   \n",
       "\n",
       "   attributes.emotion.fear  attributes.emotion.happiness  \\\n",
       "0                    0.002                        57.600   \n",
       "1                    0.012                        97.936   \n",
       "2                    0.026                        44.509   \n",
       "3                   20.876                        14.339   \n",
       "\n",
       "   attributes.emotion.neutral  attributes.emotion.sadness  \\\n",
       "0                      41.870                       0.523   \n",
       "1                       0.023                       0.083   \n",
       "2                       0.021                      54.835   \n",
       "3                      29.111                       9.857   \n",
       "\n",
       "   attributes.emotion.surprise  \n",
       "0                        0.002  \n",
       "1                        0.135  \n",
       "2                        0.172  \n",
       "3                       20.470  "
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择一张四人照\n",
    "img_url_02 = 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=895667226,563348569&fm=26&gp=0.jpg'\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url_02,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,emotion', \n",
    "}\n",
    "\n",
    "r = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "results = r.json() \n",
    "results\n",
    "\n",
    "face_df1 =  pd.json_normalize(results,record_path='faces')\n",
    "face_df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1586942829,30cf8eac-07fa-41b9-9bc3-1e54dec266d6', 'time_used': 169, 'faces': [{'face_token': '70c64744006d23ceb0f53707e86cd5f4', 'face_rectangle': {'top': 359, 'left': 714, 'width': 77, 'height': 77}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 30}, 'emotion': {'anger': 0.077, 'disgust': 4.102, 'fear': 0.077, 'happiness': 28.13, 'neutral': 4.227, 'sadness': 63.258, 'surprise': 0.128}}}, {'face_token': '2c6ef5a83434d0ed8afdd940aebe235c', 'face_rectangle': {'top': 277, 'left': 356, 'width': 68, 'height': 68}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 23}, 'emotion': {'anger': 0.002, 'disgust': 0.002, 'fear': 0.002, 'happiness': 0.026, 'neutral': 99.028, 'sadness': 0.931, 'surprise': 0.008}}}, {'face_token': '4e7b68895660a16fc4ad06720175d7a7', 'face_rectangle': {'top': 273, 'left': 537, 'width': 63, 'height': 63}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 36}, 'emotion': {'anger': 0.122, 'disgust': 0.093, 'fear': 0.027, 'happiness': 97.855, 'neutral': 0.027, 'sadness': 1.527, 'surprise': 0.35}}}, {'face_token': '9513816a4292130df055671cc856b90f', 'face_rectangle': {'top': 89, 'left': 647, 'width': 52, 'height': 52}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 29}, 'emotion': {'anger': 0.174, 'disgust': 43.332, 'fear': 18.706, 'happiness': 1.425, 'neutral': 0.264, 'sadness': 35.924, 'surprise': 0.174}}}, {'face_token': '2bce01a6a5c3df9ef2c91df6d612f4c7', 'face_rectangle': {'top': 192, 'left': 660, 'width': 52, 'height': 52}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 41}, 'emotion': {'anger': 0.001, 'disgust': 0.001, 'fear': 0.019, 'happiness': 99.957, 'neutral': 0.002, 'sadness': 0.001, 'surprise': 0.019}}}, {'face_token': '8d14db076f5cebe1c559350940923767', 'face_rectangle': {'top': 193, 'left': 414, 'width': 51, 'height': 51}}, {'face_token': '6f92ec7e17fceb23c73ee046244c821c', 'face_rectangle': {'top': 81, 'left': 727, 'width': 47, 'height': 47}}], 'image_id': 'ozxesIRuC2/GVZe+Jc+BQA==', 'face_num': 7}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <th>attributes.age.value</th>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70c64744006d23ceb0f53707e86cd5f4</td>\n",
       "      <td>359</td>\n",
       "      <td>714</td>\n",
       "      <td>77</td>\n",
       "      <td>77</td>\n",
       "      <td>Male</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.077</td>\n",
       "      <td>4.102</td>\n",
       "      <td>0.077</td>\n",
       "      <td>28.130</td>\n",
       "      <td>4.227</td>\n",
       "      <td>63.258</td>\n",
       "      <td>0.128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2c6ef5a83434d0ed8afdd940aebe235c</td>\n",
       "      <td>277</td>\n",
       "      <td>356</td>\n",
       "      <td>68</td>\n",
       "      <td>68</td>\n",
       "      <td>Male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.026</td>\n",
       "      <td>99.028</td>\n",
       "      <td>0.931</td>\n",
       "      <td>0.008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4e7b68895660a16fc4ad06720175d7a7</td>\n",
       "      <td>273</td>\n",
       "      <td>537</td>\n",
       "      <td>63</td>\n",
       "      <td>63</td>\n",
       "      <td>Female</td>\n",
       "      <td>36.0</td>\n",
       "      <td>0.122</td>\n",
       "      <td>0.093</td>\n",
       "      <td>0.027</td>\n",
       "      <td>97.855</td>\n",
       "      <td>0.027</td>\n",
       "      <td>1.527</td>\n",
       "      <td>0.350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9513816a4292130df055671cc856b90f</td>\n",
       "      <td>89</td>\n",
       "      <td>647</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "      <td>Male</td>\n",
       "      <td>29.0</td>\n",
       "      <td>0.174</td>\n",
       "      <td>43.332</td>\n",
       "      <td>18.706</td>\n",
       "      <td>1.425</td>\n",
       "      <td>0.264</td>\n",
       "      <td>35.924</td>\n",
       "      <td>0.174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2bce01a6a5c3df9ef2c91df6d612f4c7</td>\n",
       "      <td>192</td>\n",
       "      <td>660</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "      <td>Female</td>\n",
       "      <td>41.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.019</td>\n",
       "      <td>99.957</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8d14db076f5cebe1c559350940923767</td>\n",
       "      <td>193</td>\n",
       "      <td>414</td>\n",
       "      <td>51</td>\n",
       "      <td>51</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6f92ec7e17fceb23c73ee046244c821c</td>\n",
       "      <td>81</td>\n",
       "      <td>727</td>\n",
       "      <td>47</td>\n",
       "      <td>47</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  70c64744006d23ceb0f53707e86cd5f4                 359                  714   \n",
       "1  2c6ef5a83434d0ed8afdd940aebe235c                 277                  356   \n",
       "2  4e7b68895660a16fc4ad06720175d7a7                 273                  537   \n",
       "3  9513816a4292130df055671cc856b90f                  89                  647   \n",
       "4  2bce01a6a5c3df9ef2c91df6d612f4c7                 192                  660   \n",
       "5  8d14db076f5cebe1c559350940923767                 193                  414   \n",
       "6  6f92ec7e17fceb23c73ee046244c821c                  81                  727   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height attributes.gender.value  \\\n",
       "0                    77                     77                    Male   \n",
       "1                    68                     68                    Male   \n",
       "2                    63                     63                  Female   \n",
       "3                    52                     52                    Male   \n",
       "4                    52                     52                  Female   \n",
       "5                    51                     51                     NaN   \n",
       "6                    47                     47                     NaN   \n",
       "\n",
       "   attributes.age.value  attributes.emotion.anger  attributes.emotion.disgust  \\\n",
       "0                  30.0                     0.077                       4.102   \n",
       "1                  23.0                     0.002                       0.002   \n",
       "2                  36.0                     0.122                       0.093   \n",
       "3                  29.0                     0.174                      43.332   \n",
       "4                  41.0                     0.001                       0.001   \n",
       "5                   NaN                       NaN                         NaN   \n",
       "6                   NaN                       NaN                         NaN   \n",
       "\n",
       "   attributes.emotion.fear  attributes.emotion.happiness  \\\n",
       "0                    0.077                        28.130   \n",
       "1                    0.002                         0.026   \n",
       "2                    0.027                        97.855   \n",
       "3                   18.706                         1.425   \n",
       "4                    0.019                        99.957   \n",
       "5                      NaN                           NaN   \n",
       "6                      NaN                           NaN   \n",
       "\n",
       "   attributes.emotion.neutral  attributes.emotion.sadness  \\\n",
       "0                       4.227                      63.258   \n",
       "1                      99.028                       0.931   \n",
       "2                       0.027                       1.527   \n",
       "3                       0.264                      35.924   \n",
       "4                       0.002                       0.001   \n",
       "5                         NaN                         NaN   \n",
       "6                         NaN                         NaN   \n",
       "\n",
       "   attributes.emotion.surprise  \n",
       "0                        0.128  \n",
       "1                        0.008  \n",
       "2                        0.350  \n",
       "3                        0.174  \n",
       "4                        0.019  \n",
       "5                          NaN  \n",
       "6                          NaN  "
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择一张七人照\n",
    "img_url_03 = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586756754217&di=b0f52a3b6e62df4bb64eb633d780e5ef&imgtype=0&src=http%3A%2F%2Fn1.itc.cn%2Fimg8%2Fwb%2Frecom%2F2016%2F04%2F26%2F146167243273557991.JPEG'\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url_03,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,emotion', \n",
    "}\n",
    "\n",
    "r2 = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "face_r2 = r2.json() \n",
    "print(face_r2)\n",
    "\n",
    "face_df2 = pd.json_normalize(face_r2,record_path='faces')\n",
    "face_df2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- face++ 有两张人脸未能检测出信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 百度智能云\n",
    "- [百度AI官方文档](https://ai.baidu.com/ai-doc/FACE/yk37c1u4t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.2056105e1b82c456046d9d056a38c8b1.315360000.1902311087.282335-19207134', 'expires_in': 2592000, 'session_key': '9mzdXUI3X0Pju2I90k40bs12yzweNsFDZDudkQwMSeZFcYF2sFBJuHZFKE/e3TbFWO8M3eSZiAMvOpK+4gF9nNCh92g+kw==', 'access_token': '24.f6f13fae910ca961ddd7548a1b45550a.2592000.1589543087.282335-19207134', 'scope': 'public brain_all_scope vis-faceverify_faceverify_h5-face-liveness vis-faceverify_FACE_V3 vis-faceverify_idl_face_merge wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi qatest_scope1 fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': '010e4b6e0bb9ce213593d2533080c6ae'}\n"
     ]
    }
   ],
   "source": [
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=kNTwVVxlK2n6Ww7KiQmdGpvf&client_secret=tXDn4yFKggFIirFn9EKPizrw4t4356k9'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 9984554520165, 'timestamp': 1586951617, 'cached': 0, 'result': {'face_num': 1, 'face_list': [{'face_token': 'f1ae65a3ea146f544a0cc38d6bc073bc', 'location': {'left': 605.25, 'top': 366.27, 'width': 512, 'height': 506, 'rotation': -5}, 'face_probability': 1, 'angle': {'yaw': 22.11, 'pitch': 2.61, 'roll': -7.4}, 'face_shape': {'type': 'round', 'probability': 0.6}, 'age': 23, 'emotion': {'type': 'happy', 'probability': 1}}]}}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>error_code</th>\n",
       "      <th>error_msg</th>\n",
       "      <th>log_id</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>cached</th>\n",
       "      <th>result.face_num</th>\n",
       "      <th>result.face_list</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>SUCCESS</td>\n",
       "      <td>9984554520165</td>\n",
       "      <td>1586951617</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'face_token': 'f1ae65a3ea146f544a0cc38d6bc07...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   error_code error_msg         log_id   timestamp  cached  result.face_num  \\\n",
       "0           0   SUCCESS  9984554520165  1586951617       0                1   \n",
       "\n",
       "                                    result.face_list  \n",
       "0  [{'face_token': 'f1ae65a3ea146f544a0cc38d6bc07...  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "\n",
    "'''\n",
    "人脸检测与属性分析\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/face/v3/detect\"\n",
    "\n",
    "#选择一张单人照\n",
    "params = {\"image\":\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586710673935&di=0e2ba0e28894647a6f7bf59adc1a8d01&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201801%2F18%2F20180118203124_YKMew.jpeg\",\n",
    "          \"image_type\":\"URL\",\n",
    "          \"face_field\":\"faceshape,age,emotion\"\n",
    "}\n",
    "\n",
    "access_token = '24.6518b428b7e4cd6f0b698d0e92b8f674.2592000.1588350394.282335-19207134'\n",
    "request_url = request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {\n",
    "    'content-type': 'application/json',\n",
    "}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "\n",
    "response.status_code\n",
    "\n",
    "baidu_r =response.json()\n",
    "baidu_r\n",
    "\n",
    "baidu_df = pd.json_normalize(baidu_r)\n",
    "baidu_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 9489351019955, 'timestamp': 1586953228, 'cached': 0, 'result': {'face_num': 1, 'face_list': [{'face_token': '6221a64c20be7495938753a2b4bacfb6', 'location': {'left': 52.49, 'top': 50.81, 'width': 48, 'height': 46, 'rotation': 8}, 'face_probability': 1, 'angle': {'yaw': 0.17, 'pitch': -1.82, 'roll': 7.59}, 'face_shape': {'type': 'square', 'probability': 0.67}, 'age': 23, 'emotion': {'type': 'happy', 'probability': 1}}]}}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>error_code</th>\n",
       "      <th>error_msg</th>\n",
       "      <th>log_id</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>cached</th>\n",
       "      <th>result.face_num</th>\n",
       "      <th>result.face_list</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>SUCCESS</td>\n",
       "      <td>9489351019955</td>\n",
       "      <td>1586953228</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'face_token': '6221a64c20be7495938753a2b4bac...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   error_code error_msg         log_id   timestamp  cached  result.face_num  \\\n",
       "0           0   SUCCESS  9489351019955  1586953228       0                1   \n",
       "\n",
       "                                    result.face_list  \n",
       "0  [{'face_token': '6221a64c20be7495938753a2b4bac...  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择四人照\n",
    "params = {\"image\":\"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=895667226,563348569&fm=26&gp=0.jpg\",\n",
    "          \"image_type\":\"URL\",\n",
    "          \"face_field\":\"faceshape,age,emotion\"\n",
    "}\n",
    "response2 = requests.post(request_url, data=params, headers=headers)\n",
    "baidu_r2 =response2.json()\n",
    "print(baidu_r2)\n",
    "\n",
    "baidu_df2 = pd.json_normalize(baidu_r2)\n",
    "baidu_df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 13555050505, 'timestamp': 1586954278, 'cached': 0, 'result': {'face_num': 1, 'face_list': [{'face_token': 'ab3948888db511023b3281129d054af7', 'location': {'left': 703.35, 'top': 384.71, 'width': 79, 'height': 77, 'rotation': -30}, 'face_probability': 1, 'angle': {'yaw': 12.93, 'pitch': -1.52, 'roll': -32.44}, 'face_shape': {'type': 'square', 'probability': 0.52}, 'age': 22, 'emotion': {'type': 'happy', 'probability': 1}}]}}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>error_code</th>\n",
       "      <th>error_msg</th>\n",
       "      <th>log_id</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>cached</th>\n",
       "      <th>result.face_num</th>\n",
       "      <th>result.face_list</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>SUCCESS</td>\n",
       "      <td>13555050505</td>\n",
       "      <td>1586954278</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'face_token': 'ab3948888db511023b3281129d054...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   error_code error_msg       log_id   timestamp  cached  result.face_num  \\\n",
       "0           0   SUCCESS  13555050505  1586954278       0                1   \n",
       "\n",
       "                                    result.face_list  \n",
       "0  [{'face_token': 'ab3948888db511023b3281129d054...  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择七人照\n",
    "params = {\"image\":\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586756754217&di=b0f52a3b6e62df4bb64eb633d780e5ef&imgtype=0&src=http%3A%2F%2Fn1.itc.cn%2Fimg8%2Fwb%2Frecom%2F2016%2F04%2F26%2F146167243273557991.JPEG\",\n",
    "          \"image_type\":\"URL\",\n",
    "          \"face_field\":\"faceshape,age,emotion\"\n",
    "}\n",
    "response3 = requests.post(request_url, data=params, headers=headers)\n",
    "baidu_r3 =response3.json()\n",
    "print(baidu_r3)\n",
    "\n",
    "baidu_df3 = pd.json_normalize(baidu_r3)\n",
    "baidu_df3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 结论\n",
    "根据以上三家API人脸识别的检测，对比了年龄、性别、情绪。\n",
    "得出以下结论：\n",
    "\n",
    "个人认为Azure的检测结果相较于其他两家客观，精准。\n",
    " - 三家API检测的img_url_01为同一张图片，但是face++结果却差别大，其将25岁男性，识别为34岁女性\n",
    " - 其次，img_url_03为七张人脸的图，azure能够全部识别，而face++还有两张脸未能识别年龄、性别、情绪等。\n",
    " - 百度智能云无论上传几张人脸的图只能检测到一张人脸信息。\n",
    "   - 来自网络答案：百度AI人脸识别接口分为V2和V3两个版本，V3版本接口，不管几个人都指返回一张人脸的数据。（使用的正是v3接口官方文档）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
